#ifndef LINK_LIST_HPP
#define LINK_LIST_HPP

#include <cstddef>
typedef int LElemType;

typedef struct Node {
    LElemType data;
    struct Node* next;
} Node, *LinkedList;

typedef enum {
    Ok,
    Err
} Status;

class LinkList {
public:
    LinkList(LElemType e)
    {
        l = new Node;
        l->data = e;
        l->next = NULL;
    }

    bool isInit()
    {
        return l == nullptr;
    }

    Status addNode(LElemType e)
    {
        if (isInit()) {
            return Status::Err;
        }
        LinkedList newNode = new Node;
        LinkedList ptr = l;
        while (ptr->next != nullptr) {
            ptr = ptr->next;
        }
        newNode->data = e;
        newNode->next = nullptr;
        ptr->next = newNode;
        return Status::Ok;
    }

    int Max()
    {
        if (l == nullptr)
            return -1;
        LElemType tempMax = l->data;
        LinkedList ptr = l->next;
        while (ptr != nullptr) {
            tempMax = tempMax > ptr->data ? tempMax : ptr->data;
            ptr = ptr->next;
        }
        return tempMax;
    }

    int Count()
    {
        if (l == nullptr)
            return 0;
        LinkedList ptr = l;
        int count = 0;
        while (ptr != nullptr) {
            count++;
            ptr = ptr->next;
        }
        return count;
    }

    double Average()
    {
        if (l == nullptr)
            return 0;
        LinkedList ptr = l;
        int sum = 0;
        while (ptr != nullptr) {
            sum += ptr->data;
            ptr = ptr->next;
        }
        return (double)sum / (double)Count();
    }

private:
    LinkedList l;
};

#endif
